<?php
$this->breadcrumbs=array(
	'Checkpoint',
);

$menuAdmin=array(
	array('label'=>Yii::t('view', 'Monitoring'),'url'=>array('index'),'icon'=>'fa fa-list-alt', 'items' =>
		array(	
			array('label'=>Yii::t('view', 'Create Checkpoint'),'url'=>array('monitoring/create'),'icon'=>'fa fa-plus-circle'),
			array('label'=>Yii::t('view', 'List Monitoring'),'url'=>array('viewmonitoring/'),'icon'=>'fa fa-clock-o'),
		)
	)	
);

$menu=array(
           array('label'=>Yii::t('view', 'List Monitoring'),'url'=>array('viewmonitoring/'),'icon'=>'fa fa-list-ol'),
);
$this->menu = (Yii::app()->user->isAdmin() || Yii::app()->user->isWeigher()) ? $menuAdmin : $menu ;

//Yii::app()->clientScript->registerScript('checkpoint', "
//	$('#monitoring-form form').submit(function(){
//		$.fn.yiiGridView.update('checkpoint-grid', {
//			data: $(this).serialize()
//		});
//		return false;
//	});
//");
//Yii::app()->clientScript->registerScript('checkpoint-grid',
//                "setInterval(function(){;
//                    $.fn.yiiGridView.update('checkpoint-grid', {
//                        data: $(this).serialize()
//                });
//                return false;},30000);"
//);
?>

<?php $box = $this->beginWidget(
    'bootstrap.widgets.TbBox',
    array(
        'title' => Yii::t('view', 'List Checkpoint'),
        'headerIcon' => 'icon- fa fa-list-ol',
        'headerButtons' => array(
            array(
                'class' => 'bootstrap.widgets.TbButtonGroup',
                'type' => 'success',
                // '', 'primary', 'info', 'success', 'warning', 'danger' or 'inverse'
                'buttons' => $this->menu
            ),
        ) 
    )
);?>
		<?php $this->widget('bootstrap.widgets.TbAlert', array(
		    'block'=>false, // display a larger alert block?
		    'fade'=>true, // use transitions?
		    'closeText'=>'&times;', // close link text - if set to false, no close link is displayed
		    'alerts'=>array( // configurations per alert type
		        'success'=>array('block'=>true, 'fade'=>true, 'closeText'=>'&times;'), //success, info, warning, error or danger
		        'info'=>array('block'=>true, 'fade'=>true, 'closeText'=>'&times;'), //success, info, warning, error or danger
		        'warning'=>array('block'=>true, 'fade'=>true, 'closeText'=>'&times;'), //success, info, warning, error or danger
		        'error'=>array('block'=>true, 'fade'=>true, 'closeText'=>'&times;'), //success, info, warning, error or danger
		        'danger'=>array('block'=>true, 'fade'=>true, 'closeText'=>'&times;'), //success, info, warning, error or danger
		    ),
		));
		?>
<?php echo $this->renderPartial('_form', array('model'=>$model)); ?>
<?php $this->widget('bootstrap.widgets.TbGridView',array(
	'id'=>'checkpoint-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'type' => 'striped hover bordered condensed', //bordered condensed
	'columns'=>array(
		array('header'=>'#','value'=>'($this->grid->dataProvider->pagination->currentPage*
					 $this->grid->dataProvider->pagination->pageSize
					)+
					array_search($data,$this->grid->dataProvider->getData())+1',
				'htmlOptions' => array('style' =>'width: 15px'),
		),
		array(
                    'header' => '<i class="fa fa-comment"></i>',
                    'name' => 'notes',
                    'type' => 'raw',
                    'filter' => false,
                    'value' =>array($this, 'findNotes'),
                    'headerHtmlOptions'=>array('style' => 'text-align: center;' ),
                ),
		array(
                    'name' => 'noTiket',
                    'type' => 'raw',
                    'value' => '($data->noTiket)',
                    'filter' =>CHtml::activeTextField($model, 'noTiket', array('autofocus' => 'autofocus')),
                ),
		array(
                    'name' => 'timbanganMasuk',
                    'type' => 'raw',
                    'value' => 'date("H:i:s",strtotime($data->timbanganMasuk))',
                ),
		'noDokumen',
                'deskripsi',
                'noPolisi',
                'statusMobil',
		array(
                    'header' =>Yii::t('view', 'Status'),
                    'name' => 'statusParkir',
                    'type' => 'raw',
                    'value' => array($this, 'getStatusParkir'),
                ),

		array(
			'class'=>'bootstrap.widgets.TbButtonColumn',
//			'template'=>'{parking}{assign}{load}{out}{ex} {note1}{note2}{note3}{note4}', //Button action by barcode scanner
			'template'=>'{note1}{note2}{note3}{note4}',
                        'htmlOptions' => array('style' =>'width: 67px;text-align:center'),
                        'buttons'=>array
                        (
                            'note1' => array
                            (
                                'label'=>Yii::t('view', 'Add/view Note'),
                                'icon'=>'fa fa-comment-o',
                                'url'=>'array("notes/create","id"=>$data->id)',
                                'visible'=>'((Yii::app()->user->isParking() || Yii::app()->user->isAdmin()) && $data->statusParkir == 1)',
                                'options'=>array(
                                    'class'=>'badge badge-info',
                                ),
                            ),
                            'note2' => array
                            (
                                'label'=>Yii::t('view', 'Add/view Note'),
                                'icon'=>'fa fa-comment-o',
                                'url'=>'array("notes/create","id"=>$data->id)',
                                'visible'=>'((Yii::app()->user->isWarehouse() || Yii::app()->user->isAdmin()) && ($data->statusParkir == 2 || $data->statusParkir == 3))',
                                'options'=>array(
                                    'class'=>'badge badge-info',
                                ),
                            ),
                            'note3' => array
                            (
                                'label'=>Yii::t('view', 'Add/view Note'),
                                'icon'=>'fa fa-comment-o',
                                'url'=>'array("notes/create","id"=>$data->id)',
                                'visible'=>'((Yii::app()->user->isExpedition() || Yii::app()->user->isAdmin()) && $data->statusParkir == 5)',
                                'options'=>array(
                                    'class'=>'badge badge-info',
                                ),
                            ),
                            'note4' => array
                            (
                                'label'=>Yii::t('view', 'Add/view Note'),
                                'icon'=>'fa fa-comment-o',
                                'url'=>'array("notes/create","id"=>$data->id)',
                                'visible'=>'((Yii::app()->user->isWeigher() || Yii::app()->user->isAdmin()) && $data->statusParkir == 4)',
                                'options'=>array(
                                    'class'=>'badge badge-info',
                                ),
                            ),
//                            'parking' => array
//                            (
//                                'label'=>Yii::t('view', 'Confirm Parking in'),
//                                'icon'=>'fa fa-arrow-circle-right',
//                                'url'=>'array("monitoring/update","id"=>$data->id)',
//                                'visible'=>'((Yii::app()->user->isParking() || Yii::app()->user->isAdmin()) && $data->statusParkir == 1)',
//                                'options'=>array(
//                                    'class'=>'badge badge-info',
//                                ),
//                            ),
//                            'assign' => array
//                            (
//                                'label'=>Yii::t('view', 'Assign Gate'),
//                                'icon'=>'fa fa-sign-in',
//                                'url'=>'array("bongkarmuat/update","id"=>$data->tb_bongkar_muat_id)',
//                                'visible'=>'((Yii::app()->user->isWarehouse() || Yii::app()->user->isAdmin()) && $data->statusParkir == 2)',
//                                'options'=>array(
//                                    'class'=>'badge badge-info',
//                                ),
//                            ),
//                            'ex' => array
//                            (
//                                'label'=>Yii::t('view', 'Create SJ'),
//                                'icon'=>'fa fa-book',
//                                'url'=>'array("ekspedisi/create","id"=>$data->tb_bongkar_muat_id)',
//                                'visible'=>'((Yii::app()->user->isExpedition() || Yii::app()->user->isAdmin()) && ($data->statusParkir == 5 && $data->statusMobil == "Muat"))',
//                                'options'=>array(
//                                    'class'=>'badge badge-info',
//                                ),
//                            ),
//                            'load' => array
//                            (
//                                'label'=>Yii::t('view', 'Confirm Un/Load End'),
//                                'icon'=>'fa fa-check-square-o',
//                                'url'=>'array("bongkarmuat/load","id"=>$data->tb_bongkar_muat_id)',
//                                'visible'=>'((Yii::app()->user->isWarehouse() || Yii::app()->user->isAdmin()) && $data->statusParkir == 3)',
//                                'options'=>array(
//                                    'class'=>'badge badge-info',
//                                ),
//                            ),
//                            'out' => array
//                            (
//                                'label'=>Yii::t('view', 'Mobil Out'),
//                                'icon'=>'fa fa-sign-out',
//                                'url'=>'array("monitoring/out","id"=>$data->id)',
//                                'visible'=>'((Yii::app()->user->isWeigher() || Yii::app()->user->isAdmin()) && $data->statusParkir == 4)',
//                                'options'=>array(
//                                    'class'=>'badge badge-info',
//                                ),
//                            ),
                        )
		),
	),
)); ?>

<?php $this->endWidget(); ?>

<?php
$this->widget('ext.timeago.JTimeAgo', array(
    'selector' => ' .timeago',
    'settings' => array(
        'strings' => 'js:{
              prefixAgo: null,
              prefixFromNow: null,
              suffixAgo: null,
              suffixFromNow: null,
              seconds: "kurang dari semenit",
              minute: "sekitar satu menit",
              minutes: "%d menit",
              hour: "sekitar sejam",
              hours: "sekitar %d jam",
              day: "sehari",
              days: "%d hari",
              month: "sekitar sebulan",
              months: "%d tahun",
              year: "sekitar setahun",
              years: "%d tahun"
        }'
    ),
 
));

//echo CHtml::openTag('abbr',array(
//                    'class'=>'timeago',
//                     'title'=>date('c', strtotime($end)),
//                    ));
//echo CHtml::closeTag('label');
?>